<?php

namespace app\admin\controller;

use think\Db;
use think\Controller;
use Util\Sysdb;
use think\facade\Session;

class Statistics extends BaseAdmin
{
    //统计
    public function statistics()
    {
        return view('list');
    }

    //日统计
    public function day()
    {
        $ment = new \app\admin\model\Reimbursement();
        $pending = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','today')->count();//待处理
        $processed = $ment->where('status',1)->where('is_delete',0)->whereTime('create_time','today')->count();//已处理
        //待处理用户信息
        $user = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','today')->paginate(10);
        //总金额
        $pendingMoney = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','today')->value('sum(money)');
        $processedMoney = $ment->where('status',1)->where('is_delete',0)->whereTime('create_time','today')->value('sum(money)');
        $this->assign(['pending'=>$pending,'processed'=>$processed,'user'=>$user,'pendingMoney'=>$pendingMoney,'processedMoney'=>$processedMoney]);
        $this->assign('empty','<span style="color: #BD1044">没有数据</span>');
        return view('statistics');
    }

    //周统计
    public function week()
    {
        $ment = new \app\admin\model\Reimbursement();
        $pending = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','week')->count();//待处理
        $processed = $ment->where('status',1)->where('is_delete',0)->whereTime('create_time','week')->count();//已处理
        //待处理用户信息
        $user = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','week')->paginate(10);
        //总金额
        $pendingMoney = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','week')->value('sum(money)');
        $processedMoney = $ment->where('status',1)->where('is_delete',0)->whereTime('create_time','week')->value('sum(money)');
        $this->assign(['pending'=>$pending,'processed'=>$processed,'user'=>$user,'pendingMoney'=>$pendingMoney,'processedMoney'=>$processedMoney]);
        $this->assign('empty','<span style="color: #BD1044">没有数据</span>');
        return view('statistics');
    }

    //月统计
    public function month()
    {
        $ment = new \app\admin\model\Reimbursement();
        $pending = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','month')->count();//待处理
        $processed = $ment->where('status',1)->where('is_delete',0)->whereTime('create_time','month')->count();//已处理
        //待处理用户信息
        $user = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','month')->paginate(10);
        //总金额
        $pendingMoney = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','month')->value('sum(money)');
        $processedMoney = $ment->where('status',1)->where('is_delete',0)->whereTime('create_time','month')->value('sum(money)');
        $this->assign(['pending'=>$pending,'processed'=>$processed,'user'=>$user,'pendingMoney'=>$pendingMoney,'processedMoney'=>$processedMoney]);
        $this->assign('empty','<span style="color: #BD1044">没有数据</span>');
        return view('statistics');
    }

    //年统计
    public function year()
    {
        $ment = new \app\admin\model\Reimbursement();
        $pending = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','year')->count();//待处理
        $processed = $ment->where('status',1)->where('is_delete',0)->whereTime('create_time','year')->count();//已处理
        //待处理用户信息
        $user = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','year')->paginate(10);
        //总金额
        $pendingMoney = $ment->where('status',0)->where('is_delete',0)->whereTime('create_time','year')->value('sum(money)');
        $processedMoney = $ment->where('status',1)->where('is_delete',0)->whereTime('create_time','year')->value('sum(money)');
        $this->assign(['pending'=>$pending,'processed'=>$processed,'user'=>$user,'pendingMoney'=>$pendingMoney,'processedMoney'=>$processedMoney]);
        $this->assign('empty','<span style="color: #BD1044">没有数据</span>');
        return view('statistics');
    }
}